package Prova::Controller::TestCasesTags;

use strict;
use warnings;
use base 'Catalyst::Controller';
use Data::Dumper;

=head1 NAME

Prova::Controller::TestCasesTags - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut

=head2 create

create action

=cut

sub create : Private {
    my ( $self, $c, $test_case_id, $tag_ids ) = @_;

    # save relations after deleting before data.
#    $self->remove_tags( $c, $test_case_id );

    my @tags;
    if ( ref $tag_ids eq 'ARRAY' and @$tag_ids ) {
        for my $tag_id ( @$tag_ids ) {
            my $testcases_tags = $c->model( 'DBIC::TestcasesTags' )->create( {
                                                                              test_case_id => $test_case_id,
                                                                              tags_id => $tag_id
                                                                          } );
            push @tags, $testcases_tags;
        }
    }
    return \@tags;
}

=head2 remove_tags

=cut

sub remove_tags : Private {
    my ( $self, $c, $test_case_id ) = @_;

    $c->model( 'DBIC::TestcasesTags' )->search( {
                                                 test_case_id => $test_case_id
                                             } )->delete;
}

=head1 AUTHOR

Shanon Inc, E<lt>http://www.shanon.co.jp/E<gt>

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
